//
//  XiaoXiViewController.m
//  CarPark
//
//  Created by oceans on 2019/8/19.
//  Copyright © 2019 oceans. All rights reserved.
//

#import "XiaoXiViewController.h"
#import "TaskXiaoXiViewController.h"
#import "ChipXiaoXiViewController.h"
#import "ReviewViewController.h"
#import "NotifiViewController.h"

@interface XiaoXiViewController () <UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) UITableView *tableview;
@property (strong, nonatomic) NSArray *array;
@end

@implementation XiaoXiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupView];
    
    [self loadData];
}

- (void)loadData {
    
    defweakself
    [HttpRequest getURL:knotifi_center paras:nil showProgress:NO successful:^(id  _Nullable result) {
        NSLog(@"%@", result);
        weakself.array = result[@"datas"];
        [weakself.tableview reloadData];
    } failed:^(int code, NSString * _Nullable errMsg) {
        
    }];
}

- (void)setupView {
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"消息列表";
    
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, XNavigationHeight, ScreenWidth, ScreenHeight-XNavigationHeight) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self.view addSubview:_tableview];
    
    _tableview.tableFooterView = [[UIView alloc] init];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _array.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 50.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    NSDictionary *dic = _array[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@ (%@)", dic[@"type_label"], dic[@"type_nums"]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *dic = _array[indexPath.row];
    if ([dic[@"type"] isEqualToString:@"task"]) {
        
        TaskXiaoXiViewController *con = [[TaskXiaoXiViewController alloc] init];
        [self.navigationController pushViewController:con animated:YES];
    }else if ([dic[@"type"] isEqualToString:@"rfid_warning"]) {
        
        
        ChipXiaoXiViewController *con = [[ChipXiaoXiViewController alloc] init];
        [self.navigationController pushViewController:con animated:YES];
    }else if ([dic[@"type"] isEqualToString:@"verify"]) {
        
        ReviewViewController *con = [[ReviewViewController alloc] init];
        [self.navigationController pushViewController:con animated:YES];
    }else if ([dic[@"type"] isEqualToString:@"notice"]) {
        
        NotifiViewController *con = [[NotifiViewController alloc] init];
        [self.navigationController pushViewController:con animated:YES];
    }
}

@end
